import type { CollectionTask } from './model';

import type { ID, PageQuery, PageResult } from '#/api/common';

import { requestClient } from '#/api/request';

enum Api {
  collectionTaskAdd = '/crawler/crawlerTask/add',
  collectionTaskInfo = '/crawler/crawlerTask/getById?crawlerTaskId=',
  collectionTaskList = '/crawler/crawlerTask/queryByPage',
  collectionTaskRemove = '/crawler/crawlerTask/deleteTask?id=',
  collectionTaskStart = '/crawler/crawlerTask/startCrawler?id=',
  collectionTaskStop = '/crawler/crawlerTask/stopCrawler?id=',
  collectionTaskUpdate = '/crawler/crawlerTask/update',

  root = '/crawler/crawlerTask',
}

/**
 * 系统参数分页列表
 * @param params 请求参数
 * @returns 列表
 */
export function collectionTaskList(params?: PageQuery) {
  return requestClient.get<PageResult<CollectionTask>>(Api.collectionTaskList, {
    params,
  });
}

export function collectionTaskInfo(collectionTaskId: ID) {
  return requestClient.get<CollectionTask>(
    `${Api.collectionTaskInfo}${collectionTaskId}`,
  );
}
/**
 * 启动任务
 * @param data 参数
 */
export function collectionTaskStart(collectionTaskId: ID) {
  return requestClient.putWithMsg<void>(
    `${Api.collectionTaskStart}${collectionTaskId}`,
  );
}
/**
 * 暂停任务
 * @param data 参数
 */
export function collectionTaskStop(collectionTaskId: ID) {
  return requestClient.putWithMsg<void>(
    `${Api.collectionTaskStop}${collectionTaskId}`,
  );
}
/**
 * 更新采集任务
 * @param data 参数
 */
export function collectionTaskUpdate(data: Partial<CollectionTask>) {
  return requestClient.putWithMsg<void>(Api.collectionTaskUpdate, data);
}

/**
 * 新增采集任务
 * @param data 参数
 */
export function collectionTaskAdd(data: Partial<CollectionTask>) {
  return requestClient.postWithMsg<void>(Api.collectionTaskAdd, data);
}

/**
 * 删除配置
 * @param collectionTaskIds ids
 */
export function collectionTaskRemove(collectionTaskIds: ID) {
  return requestClient.deleteWithMsg<void>(
    `${Api.collectionTaskRemove}${collectionTaskIds}`,
  );
}

// /**
//  * 获取配置信息
//  * @param collectionTaskKey collectionTaskKey
//  * @returns value
//  */
// export function collectionTaskInfoByKey(collectionTaskKey: string) {
//   return requestClient.get<string>(
//     `${Api.collectionTaskInfoByKey}/${collectionTaskKey}`,
//   );
// }
